package com.tensquare.qa.service;

import com.tensquare.qa.dao.ProblemDao;
import com.tensquare.qa.pojo.Problem;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WF on 2020/7/22 15:47
 */
@Service
public class ProblemService {
    @Autowired
    private ProblemDao problemDao;
    //1.查询最新问题列表
    public PageResult<Problem> newlist(String labelId, int page, int size) {
        //1.1)查询最新问题列表
        Page<Problem> problemPage = problemDao.findProblemsByLabelId(labelId, PageRequest.of(page - 1, size));
        //1.2)返回分页对象
        return new PageResult<>(problemPage.getTotalElements(),problemPage.getContent());
    }
    //2.查询热门问题列表
    public PageResult<Problem> hotList(String labelId, int page, int size) {
        //2.1)查询热门问题列表
        Page<Problem> hostList = problemDao.findHostList(labelId, PageRequest.of(page - 1, size));
        //2.2)返回
        return new PageResult<>(hostList.getTotalElements(),hostList.getContent());
    }
    //3.查询所有问题列表
    public List<Problem> findAll() {
        return problemDao.findAll();
    }
}
